﻿namespace Om.Core.Extension;

public static class LogHelper
{
    public static void Log(string msg)
    {
        LogToFile(msg);
    }


    public static void Log(Exception e)
    {
        var txt = @$"Msg:{e.Message}
StackTrace:{e.StackTrace}";
        LogToFile(txt);
    }

    private static void LogToFile(string msg)
    {
        var filePath = @$"./log/log_{DateTime.Today:yyyyMMdd}.log";
        var directory = Path.GetDirectoryName(filePath);
        Directory.CreateDirectory(directory);
        var txt = @$"{DateTime.Now:yyyy-MM-dd HH:mm:ss}
{msg}";
        using (StreamWriter writer = File.AppendText(filePath))
        {
            writer.WriteLine(txt);
        }
    }
}